﻿
namespace ComponentEngine_12_12_2014 {

	public static class Behaviors {

		public static void Think(ref Entity entity) {
			if (entity.MindType == MindType.Enemy) {
				entity.MovementState = MovementState.Walking;
			}
		}

		public static void Move(ref Entity entity) {
			if (entity.MovementState == MovementState.Walking) {
				entity.Position.X += ((float) MyGame.GameTime.ElapsedGameTime.TotalSeconds*entity.Speed*(int) entity.HorizontalDirection);
			}
		}

		public static void Animate(ref Entity entity) {

			Animation animation = entity.Animation; // VALUE type! No garbage collection, at least. Does have to allocate memory though.

			if (animation.IsDone) {
				animation.IsDone = false;
				animation.CurrentFrame = 0;
			}

			entity.Texture = animation.Frames[animation.CurrentFrame];

			animation.FrameElapsedSeconds += (float) MyGame.GameTime.ElapsedGameTime.TotalSeconds;
			if (animation.FrameElapsedSeconds > animation.FrameSeconds[animation.CurrentFrame]) {
				animation.FrameElapsedSeconds -= animation.FrameSeconds[animation.CurrentFrame];
				animation.CurrentFrame++;
				if (animation.CurrentFrame == animation.NumFrames) {
					animation.IsDone = true;
				}
			}

			entity.Animation = animation; // VALUE type!
		}

	}

}